﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:MediaBrowser.CustomWindow"
    xmlns:MouseCursors="clr-namespace:MediaBrowser.CustomControls.MouseCursors;assembly=MediaBrowser.CustomControls"
    xmlns:EffectsLib="clr-namespace:EffectsLib;assembly=EffectsLib" 
    x:Class="MediaBrowser.CustomWindow.CustomWindowStyleEvent"
    x:ClassModifier="internal">

    <LinearGradientBrush x:Key="TitleBarBackgroundBrush" EndPoint="0.5,1" StartPoint="0.5,0">
        <GradientStop Color="#FF1B1B1B" Offset="0.004"/>
        <GradientStop Color="#FF42566A" Offset="1"/>
    </LinearGradientBrush>

    <SolidColorBrush x:Key="BorderBrush" Color="#FF0E0C0C" />

    <Style TargetType="{x:Type local:ImageButton}">
        <Setter Property="Focusable" Value="false" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:ImageButton}">
                    <Border VerticalAlignment="Top" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                        <Image Name="PART_img" Source="{Binding Path=ImageNormal, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"  />
                    </Border>

                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Source" Value="{Binding Path=ImageOver, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" TargetName="PART_img"/>
                        </Trigger>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter Property="Source" Value="{Binding Path=ImageDown, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" TargetName="PART_img"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type local:TitleBar}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:TitleBar}">
                    <Border Name="TitleBar" DockPanel.Dock="Top" Background="{StaticResource TitleBarBackgroundBrush}" BorderThickness="0,0,0,1" BorderBrush="{StaticResource BorderBrush}" CornerRadius="5,5,0,0"  >
                        <Grid Height="24">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="22"/>
                                <ColumnDefinition />
                                <ColumnDefinition Width="34"/>
                                <ColumnDefinition Width="34"/>
                                <ColumnDefinition Width="44"/>
                            </Grid.ColumnDefinitions>

                            <Image Grid.Column="0" Name="Icon" Source="{Binding Path=Icon, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" 
                            HorizontalAlignment="Right" Margin="5,0,0,0" Width="16" Height="16" />

                            <TextBlock Grid.Column="1" Name="Caption" Foreground="WhiteSmoke" FontFamily="Calibri"  HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5,0,0,0"
                            FontSize="12" Text="{Binding Path=Title, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" />

                            <local:ImageButton Grid.Column="2" x:Name="MinButton" Hidden="{TemplateBinding HiddenMinimumBox}" ImageNormal="/MediaBrowser.CustomWindow;Component/Images/min.png" ImageOver="/MediaBrowser.CustomWindow;Component/Images/minhot.png" 
                             ImageDown="/MediaBrowser.CustomWindow;Component/Images/minpressed.png" Width="34" Height="19"/>

                            <local:ImageButton Grid.Column="3" x:Name="MaxButton" Hidden="{TemplateBinding HiddenMaximizeBox}"  ImageNormal="/MediaBrowser.CustomWindow;Component/Images/max_n.png" ImageOver="/MediaBrowser.CustomWindow;Component/Images/maxhot_n.png" 
                             ImageDown="/MediaBrowser.CustomWindow;Component/Images/maxpressed_n.png" Width="34" Height="19" />

                            <local:ImageButton Grid.Column="4" x:Name="CloseButton" ImageNormal="/MediaBrowser.CustomWindow;Component/Images/close_n.png" ImageOver="/MediaBrowser.CustomWindow;Component/Images/closehot_n.png" 
                            ImageDown="/MediaBrowser.CustomWindow;Component/Images/closepressed_n.png" Width="44" Height="19" />
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type Border}" x:Key = "MainBorder">
        <Setter Property="Background" Value="{x:Null}" />
        <Setter Property="BorderBrush" >
            <Setter.Value>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FF6C6F7A" Offset="0"/>
                    <GradientStop Color="#FF6C6F7A" Offset="1"/>
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="CornerRadius" Value="3" />
        <Setter Property="Padding" Value="3"/>
    </Style>

    <Style TargetType="{x:Type local:CustomWindowStyle}">
        <Setter Property="AllowsTransparency" Value="true" />
        <Setter Property="WindowStyle" Value="None" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:CustomWindowStyle}">
                    <ControlTemplate.Resources>
                        <Storyboard x:Key="AnimEnableOn" AccelerationRatio="0.5" DecelerationRatio="0.5" >
                            <DoubleAnimation BeginTime="00:00:00" From="-0.5"  To="0" Duration="00:00:00.25"  
                                             Storyboard.TargetName="contentPresenter" 
                                             Storyboard.TargetProperty="(UIElement.Effect).(EffectsLib:BrightContrastEffect.Contrast)"/>
                        </Storyboard>
                        <Storyboard x:Key="AnimEnableOff" AccelerationRatio="0.5" DecelerationRatio="0.5" >
                            <DoubleAnimation BeginTime="00:00:00" From="0"  To="-0.5" Duration="00:00:00.25"   
                                             Storyboard.TargetName="contentPresenter" 
                                             Storyboard.TargetProperty="(UIElement.Effect).(EffectsLib:BrightContrastEffect.Contrast)"/>
                        </Storyboard>
                    </ControlTemplate.Resources>
                    <Grid>
                        <Border Width="Auto" Height="Auto" Style="{StaticResource MainBorder}">
                            <DockPanel HorizontalAlignment="Stretch" Background="Transparent" VerticalAlignment="Stretch">
                                <local:TitleBar HiddenMaximizeBox="{TemplateBinding HiddenMaximizeBox}" 
                                                HiddenMinimumBox="{TemplateBinding HiddenMinimumBox}"
                                                DockPanel.Dock="Top" 
                                                Title="{TemplateBinding Title}" 
                                                Icon="{TemplateBinding Icon}" />
                                <ContentPresenter x:Name="contentPresenter">
                                    <ContentPresenter.Effect>
                                        <EffectsLib:BrightContrastEffect x:Name="brightContrastEffect"/>
                                    </ContentPresenter.Effect>
                                </ContentPresenter>
                            </DockPanel>
                        </Border>

                        <Line MouseDown="OnSizeNorth" x:Name="lnSizeNorth" Stroke="Transparent" MouseCursors:CursorSet.Cursor="SizeNS" X1="10" X2="{TemplateBinding ActualWidth}" Y1="1" Y2="1" StrokeThickness="2"  />
                        <Line MouseDown="OnSizeSouth" x:Name="lnSizeSouth" Stroke="Transparent" VerticalAlignment="Bottom" MouseCursors:CursorSet.Cursor="SizeNS" X1="1" X2="{TemplateBinding ActualWidth}" Y1="{TemplateBinding ActualHeight}" Y2="{TemplateBinding ActualHeight}" StrokeThickness="2" />
                        <Line MouseDown="OnSizeWest" x:Name="lnSizeWest" Stroke="Transparent" MouseCursors:CursorSet.Cursor="SizeWE" X1="1" X2="1" Y1="1" Y2="{TemplateBinding ActualHeight}"  StrokeThickness="2" />
                        <Line MouseDown="OnSizeEast" x:Name="lnSizeEast" Stroke="Transparent" HorizontalAlignment="Right" MouseCursors:CursorSet.Cursor="SizeWE" X1="{TemplateBinding ActualWidth}" X2="{TemplateBinding ActualWidth}" Y1="1" Y2="{TemplateBinding ActualHeight}"  StrokeThickness="2" />

                        <Rectangle MouseDown="OnSizeNorthWest" x:Name="rectSizeNorthWest" MouseCursors:CursorSet.Cursor="SizeNWSE" Fill="Transparent" Width="5" Height="5" VerticalAlignment="Top" HorizontalAlignment="Left" />
                        <Rectangle MouseDown="OnSizeNorthEast" x:Name="rectSizeNorthEast" MouseCursors:CursorSet.Cursor="SizeNESW" Fill="Transparent" Width="5" Height="5" VerticalAlignment="Top" HorizontalAlignment="Right" />
                        <Rectangle MouseDown="OnSizeSouthWest" x:Name="rectSizeSouthWest" MouseCursors:CursorSet.Cursor="SizeNESW" Fill="Transparent" Width="5" Height="5" VerticalAlignment="Bottom" HorizontalAlignment="Left" />
                        <Rectangle MouseDown="OnSizeSouthEast" x:Name="rectSizeSouthEast" MouseCursors:CursorSet.Cursor="SizeNWSE" Fill="Transparent" Width="5" Height="5" VerticalAlignment="Bottom" HorizontalAlignment="Right" />
                        <Image x:Name="PART_img_Resize" MouseDown="OnSizeSouthEast" MouseCursors:CursorSet.Cursor="SizeNWSE" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="0,0,5,5" Width="16" Height="16"  />
                    </Grid>

                    <ControlTemplate.Triggers>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="HiddenMaximizeBox" Value="False" />
                                <Condition Property="ResizeMode" Value="CanResizeWithGrip" />
                            </MultiTrigger.Conditions>
                            <Setter Property="Source" Value="/MediaBrowser.CustomWindow;Component/Images/resize.png" TargetName="PART_img_Resize"/>
                        </MultiTrigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Trigger.EnterActions>
                                <BeginStoryboard Storyboard="{StaticResource AnimEnableOff}" />
                            </Trigger.EnterActions>
                            <Trigger.ExitActions>
                                <BeginStoryboard Storyboard="{StaticResource AnimEnableOn}" />
                            </Trigger.ExitActions>
                        </Trigger>
                    </ControlTemplate.Triggers>

                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>



</ResourceDictionary>
